package com.example.win.android_banduyujia.peopleactivity.activity.activity.openactivity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.adapter.ImageBucketAdapter;
import com.example.win.android_banduyujia.entity.ImageBucket;
import com.example.win.android_banduyujia.peopleactivity.helper.AlbumHelper;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Win on 2015/9/10.
 */
public class TestPicActivity  extends Activity {

    List<ImageBucket>  dataList;
    GridView   gridView;
    ImageBucketAdapter adapter; // 自定义的适配器
    AlbumHelper helper;
    public static final String EXTRA_IMAGE_LIST = "imagelist";
    public static Bitmap bimap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_image_bucket);

        helper = AlbumHelper.getHelper();
        helper.init(getApplicationContext());

        initData();
        initViews();
    }

    /**
     * 初始化数据
     */
    private void initData() {
         dataList = helper.getImagesBucketList(false);
         bimap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_addpic_unfocused);
    }

    /**
     * 初始化view视图
     */
    private void initViews() {
        gridView=(GridView)findViewById(R.id.title_grid_view);
        adapter = new ImageBucketAdapter(TestPicActivity.this, dataList);
        gridView.setAdapter(adapter);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                /**
                 * 通知适配器，绑定的数据发生了改变，应当刷新视图
                 */
                Intent intent=new Intent(TestPicActivity.this, ImageGridActivity.class);
                intent.putExtra(TestPicActivity.EXTRA_IMAGE_LIST, (Serializable)dataList.get(position).imageList);
                startActivity(intent);
                finish();
            }
        });
    }
}
